<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>Ionic App</title>
    <base href="./"/>
    <meta name="color-scheme" content="light dark"/>
    <meta name="viewport" content="viewport-fit=cover,width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="msapplication-tap-highlight" content="no"/>
    <link rel="shortcut icon" type="image/png" href="./ionic/assets/icon/favicon.png"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-title" content="Ionic App"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    
    <link href="./ionic/css/chunk-ionic.f5c8e0e3.css" rel="stylesheet">
    <link href="./ionic/css/app.7b141fc5.css" rel="stylesheet">
    
    <style>
        .debug-info {
            position: fixed;
            top: 10px;
            right: 10px;
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 8px;
            border-radius: 4px;
            font-size: 11px;
            z-index: 9999;
            max-width: 200px;
            max-height: 150px;
            overflow-y: auto;
        }
        
        /* 确保应用在加载时有基本样式 */
        #app {
            width: 100%;
            height: 100vh;
            overflow: hidden;
        }
        
        /* 加载提示 */
        #app:empty::before {
            content: "正在启动应用...";
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
            color: #666;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div id="app"></div>
    
    <div class="debug-info" id="debug">
        <div>🔄 启动中...</div>
    </div>
    
    <script>
        console.log('=== Ionic App Fixed Version ===');
        
        const debug = document.getElementById('debug');
        let messages = [];
        
        function log(msg) {
            console.log(msg);
            messages.push(new Date().toLocaleTimeString().slice(-8) + ': ' + msg);
            debug.innerHTML = messages.slice(-5).map(m => '<div style="margin:1px 0;">' + m + '</div>').join('');
        }
        
        // 环境变量修复
        if (typeof process === 'undefined') {
            window.process = {
                env: {
                    BASE_URL: './',
                    NODE_ENV: 'production'
                }
            };
            log('✅ 环境变量已修复');
        }
        
        // 监听应用挂载
        const observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.target.id === 'app' && mutation.target.children.length > 0) {
                    log('✅ 应用已渲染');
                    
                    // 检查是否有路由内容
                    setTimeout(() => {
                        const routerView = document.querySelector('ion-router-outlet, router-view, [role="main"]');
                        if (routerView) {
                            log('✅ 路由组件已加载');
                        } else {
                            log('⚠ 路由组件未找到');
                        }
                        
                        // 3秒后隐藏调试信息
                        setTimeout(() => {
                            debug.style.display = 'none';
                        }, 3000);
                    }, 1000);
                }
            });
        });
        
        observer.observe(document.getElementById('app'), {
            childList: true,
            subtree: true
        });
        
        // 错误处理
        window.addEventListener('error', (e) => {
            log('❌ ' + e.message.substring(0, 30));
        });
        
        window.addEventListener('unhandledrejection', (e) => {
            log('❌ Promise: ' + String(e.reason).substring(0, 20));
        });
        
        // 路由变化监听
        let lastHash = location.hash;
        function checkRoute() {
            if (location.hash !== lastHash) {
                lastHash = location.hash;
                log('🔄 路由: ' + (lastHash || '/'));
            }
        }
        setInterval(checkRoute, 1000);
        
        log('✅ 页面初始化完成');
        
        window.addEventListener('load', () => {
            log('✅ 资源加载完成');
        });
    </script>
    
    <!-- 使用 Legacy 版本以确保兼容性 -->
    <script defer="defer" src="./ionic/js/chunk-ionic-legacy.b2c76632.js" nomodule></script>
    <script defer="defer" src="./ionic/js/chunk-vendors-legacy.30a74f52.js" nomodule></script>
    <script defer="defer" src="./ionic/js/app-legacy.55c5c7f4.js" nomodule></script>
</body>
</html>